package liuwanghui.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import liuwanghui.dto.request.*;
import liuwanghui.pojo.Result;
import liuwanghui.service.ConsumerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/consumer")
@RequiredArgsConstructor
@Tag(name = "消费者管理", description = "消费者相关接口")
public class ConsumerController {

    private final ConsumerService consumerService;

    @GetMapping("/market")
    @Operation(summary = "获取市场商品列表")
    public Result getMarketProducts(@ModelAttribute MarketQueryDTO params) {
        return consumerService.getMarketProducts(params);
    }

    @GetMapping("/market/{id}")
    @Operation(summary = "获取商品详情")
    public Result getProductDetail(@PathVariable Long id) {
        return consumerService.getProductDetail(id);
    }

    @PostMapping("/orders")
    @Operation(summary = "创建订单")
    public Result createOrder(@RequestBody @Valid ConsumerOrderCreateDTO dto) {
        return consumerService.createOrder(dto);
    }

    @GetMapping("/statistics/dashboard")
    @Operation(summary = "获取仪表盘统计数据")
    public Result getDashboardStats(
            @RequestParam(required = false, defaultValue = "7d") String timeRange,
            @RequestParam(required = false, defaultValue = "true") Boolean includeOrders,
            @RequestParam(required = false, defaultValue = "true") Boolean includeExpenses,
            @RequestParam(required = false, defaultValue = "true") Boolean includeFavorites,
            @RequestParam(required = false, defaultValue = "true") Boolean includeCategories) {
        return consumerService.getDashboardStats(timeRange, includeOrders, includeExpenses, 
            includeFavorites, includeCategories);
    }
} 